package com.example.administrator.familfinalcialmanagement.ui;

import android.content.Intent;
import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.text.TextUtils;
import android.view.View;

import com.example.administrator.familfinalcialmanagement.MainActivity;
import com.example.administrator.familfinalcialmanagement.R;
import com.example.administrator.familfinalcialmanagement.bean.UserInfoBean;
import com.example.administrator.familfinalcialmanagement.databinding.ActivityRegisterBinding;
import com.example.administrator.familfinalcialmanagement.ui.view.RegisterTime;
import com.example.administrator.familfinalcialmanagement.util.SpUtils;
import com.example.administrator.familfinalcialmanagement.util.ToastUtil;
/**
 * Created by Administrator on 2019/3/26.
 */

public class RegisterActivity extends BaseActivity {

    ActivityRegisterBinding binding;
    RegisterTime timeUtil;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        binding = DataBindingUtil.setContentView(this, R.layout.activity_register);
        binding.setActivity(this);
        initView();
    }

    private void initView() {
        setBack();
        setTitleText("注册");
        binding.textViewUpdata.setOnClickListener(this);
    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        if (timeUtil != null) {
            timeUtil.onCancel();
        }
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.textViewUpdata:
                String PhoneCode = binding.phone.getText().toString().trim();
                if (TextUtils.isEmpty(PhoneCode)) {
                    ToastUtil.showToast( "请输入账号" );
                    return;
                }

                String pwd = binding.pwd.getText().toString().trim();
                if (TextUtils.isEmpty( pwd )) {
                    ToastUtil.showToast( "请输入密码" );
                    return;
                }

                String pwdAgain = binding.pwdAgain.getText().toString().trim();
                if (TextUtils.isEmpty( pwdAgain )) {
                    ToastUtil.showToast( "请确认密码" );
                    return;
                }

                if (!pwd.equals( pwdAgain )) {
                    binding.pwdAgain.setText( "" );
                    ToastUtil.showToast( "两次输入不一致" );
                    return;
                }

                UserInfoBean bean = new UserInfoBean();
                bean.setName( PhoneCode );
                bean.setPwd( pwd );
                SpUtils.putBean( "user_info_bean",bean );

                Intent intent = new Intent(  RegisterActivity.this, MainActivity.class );
                intent.putExtra( "module_phone",PhoneCode );
                intent.putExtra( "module_pwd",pwd );
                startActivity(intent);
                break;
            default:
        }
    }
}
